<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/layui/css/layui.css">
        <link rel="stylesheet" href="../../global/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
        <link rel="stylesheet" href="../../global/css/ztree/demo.css" type="text/css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form" enctype="multipart/form-data">
        <fieldset>
     <input type="hidden" id="shopsId" name="shopsId"/>
          <div class="form-group">
           <label class="col-md-2 control-label">商铺名称:</label>
           <div class="col-md-5">
            <input class="form-control" placeholder="商铺名称" type="text" name="shopsName" id="shopsName" data-bv-notempty="true" data-bv-notempty-message="商铺名称不能为空" />
           </div>
          </div>
            <div class="form-group">
                                  <label class="col-md-2 control-label">店铺类型:</label>
                                  <div class="col-md-10" style="width: 120px">
                                      <ul id="treeDemo" class="ztree"></ul>
                              </div>
                              </div>
            <div class="form-group">
                <label class="col-md-2 control-label">logo:</label>
                <div class="col-md-10">
                    <img id="logo1" />
                    <input type="file" name="logo1" />
                </div>
            </div>
           <div class="form-group">
                                <label class="col-md-2 control-label">店铺简介:</label>
                                <div class="col-md-5">
                                <textarea  name="property" id="property"  rows="10" cols="30">
                                </textarea>
                                </div>
                                </div>
            <div class="form-group">
                           <label class="col-md-2 control-label">客服电话:</label>
                           <div class="col-md-5">
                               <input class="form-control" placeholder="联系方式" type="text" name="phone" id="phone"  />
                           </div>
                       </div>
             <div class="form-group">
                            <label class="col-md-2 control-label">商铺所在省:</label>
                            <div class="col-md-5">
                                <input readonly class="form-control" placeholder="商铺所在省" type="text" name="shopProvince" id="shopProvince" data-bv-notempty="true" data-bv-notempty-message="商铺所在省不能为空" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">商铺所在市:</label>
                            <div class="col-md-5">
                                <input readonly class="form-control" placeholder="商铺所在市" type="text" name="shopCity" id="shopCity" data-bv-notempty="true" data-bv-notempty-message="商铺所在市不能为空" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">商铺所在县/区:</label>
                            <div class="col-md-5">
                                <input readonly class="form-control" placeholder="商铺所在县/区" type="text" name="shopCountry" id="shopCountry" data-bv-notempty="true" data-bv-notempty-message="商铺所在县/区不能为空" />
                            </div>
                        </div>
            <div class="form-group">
                <label class="col-md-2 control-label">店铺地址:</label>
                <div class="col-md-5">
                     <input type="text" readonly placeholder="位置" style="width:600px" id="shopsAddress" name="shopsAddress" /><input readonly type="text" placeholder="经度" id="lng" name="lng" /><input readonly type="text" placeholder="纬度" id="lat" name="lat" />
            		<div id="container2" style="width:100%;height:300px"></div>
                </div>
            </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='clyjNearbyShops.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="update()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../global/js/common.js"></script>
<script type="text/javascript" src="../../global/js/libs/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="../../global/layui/layui.js"></script>
<script type="text/javascript" src="../../global/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="../../global/js/my/ztree-menu.js"></script>
<script type="text/javascript"
	src="https://webapi.amap.com/maps?v=1.4.10&key=5f80e00b3a03bce6ac34804ff562a19f"></script>
<script type="text/javascript"
	src="https://webapi.amap.com/demos/js/liteToolbar.js"></script>
<script src="https://webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script>
<script type="text/javascript">
    layui.use(['layer', 'laydate'], function () {
        var layer = layui.layer;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#aptitudeTime'
        });
    });
    $.fn.zTree.init($("#treeDemo"), getSettting2(), getMenuTree3());
    $(function(){
		initData();
	    loadmap();
	})
    function initData() {
    	var shopsType;
         var id = getUrlParam("id");
         if (id != "") {
            $.ajax({
                type: 'get',
                url: '/clyjNearbyShops/' + id,
                async: false,
                success: function (result) {
                    var data = result.data;
                     $("#shopsId").val(data.shopsId);
                     $("#shopsName").val(data.shopsName);
                     $("#logo1").attr("src",data.logo);
                     $("#shopsType").val(data.shopsType);
                     $("#property").val(data.property);
                     $("#phone").val(data.phone);
                     $("#shopProvince").val(data.shopProvince);
                     $("#shopCity").val(data.shopCity);
                     $("#shopCountry").val(data.shopCountry)
                     $("#shopsAddress").val(data.shopsAddress);
                     shopsType=data.shopsType;
                    }
            
            });
            initMenuDatas4(shopsType);
        }
        }
    $('#form').bootstrapValidator();

    function update() {
        // 表单验证
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }
     var ids = getCheckedMenuIds2()

        $("form").ajaxSubmit({
            type: 'post',
            url: '/clyjNearbyShops/updateShopsList',
            data:{"typeIds":ids},
            traditional: true,
            contentType: "application/json; charset=utf-8",
            //data: JSON.stringify(formdata),
            success: function (data) {
                layer.msg("修改成功", {shift: -1, time: 1000}, function () {
                    location.href = "updateNearbyShops.html";
                });
            }
        });
    }
    function loadmap() {
		var map = new AMap.Map('container2', {
			resizeEnable : true,
			zoom : 11,
			scrollWheel : true
		});
		var marker = new AMap.Marker(
				{
					position : [ $("#longitude").val(),
							$("#latitude").val() ],
					content : '<div class="markers_tip bdz_markers"><div>111</div></div>',
					offset : new AMap.Pixel(-25, -45)
				});
		mapInit(map);
		$(".loadmap:eq(1)").hide();

	}
    function mapInit(map) {
		AMap.plugin('AMap.Geolocation', function() {
			geolocation = new AMap.Geolocation({
				enableHighAccuracy : true, //是否使用高精度定位，默认:true
				timeout : 10000, //超过10秒后停止定位，默认：无穷大
				maximumAge : 0, //定位结果缓存0毫秒，默认：0
				convert : true, //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
				showButton : true, //显示定位按钮，默认：true
				buttonPosition : 'RT', //定位按钮停靠位置，默认：'LB'，左下角
				buttonOffset : new AMap.Pixel(10, 10), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
				showMarker : true, //定位成功后在定位到的位置显示点标记，默认：true
				panToLocation : true, //定位成功后将定位到的位置作为地图中心点，默认：true
				zoomToAccuracy : true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
			});
			map.addControl(geolocation);
			geolocation.getCurrentPosition();
			AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
			AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
		});
		

		function onComplete(data) { //地图实时定位结果
			var str = [ '定位成功' ];
			str.push('经度：' + data.position.getLng());
			str.push('纬度：' + data.position.getLat());
			if (data.accuracy) {
				str.push('精度：' + data.accuracy + ' 米');
			} //如为IP精确定位结果则没有精度信息
			str.push('是否经过偏移：' + (data.isConverted ? '是' : '否'));
			AMapUI
					.loadUI(
							[ 'misc/PositionPicker' ],
							function(PositionPicker) {
								var positionPicker = new PositionPicker(
										{
											map : map,
											iconStyle : { //自定义外观
												url : 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png', //webapi.amap.com/ui/1.0/assets/position-picker2.png
												ancher : [ 12, 38 ],
												size : [ 19, 31 ]
											}
										});
								positionPicker.on('success', function(
										positionResult) {
									console.info(positionResult);
									$("#shopsAddress").val(
											positionResult.address);
									$("#lng").val(
											positionResult.position.lng);
									$("#lat").val(
											positionResult.position.lat);
									$("#shopProvince").val(
											positionResult.regeocode.addressComponent.province);
									$("#shopCity").val(
											positionResult.regeocode.addressComponent.city);
									$("#shopCountry").val(
											positionResult.regeocode.addressComponent.district);
								});
								positionPicker.on('fail', function(
										positionResult) {

								});
								positionPicker.start();
							});
		}

		function onError(data) { //解析定位错误信息
			$("#addressInfo").text("定位失败");
		}
	}

</script>
</body>
</html>